package io.bdmc.modules.bss.controller;

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.bdmc.common.annotation.SysLogger;
import io.bdmc.common.utils.R;
import io.bdmc.modules.bss.entity.DeviceLink;
import io.bdmc.modules.bss.service.IDeviceLinkService;
import io.bdmc.modules.sys.controller.AbstractController;

/**
 * <p>
 * 链路视图 前端控制器
 * </p>
 *
 * @author 黄露
 * @since 2021-06-25
 */

// "链路视图", description = "链路视图")
@RestController
@RequestMapping("/bss/link")
public class DeviceLinkController extends AbstractController {

	@Autowired
	IDeviceLinkService _devicelinkSvs;

	@GetMapping("/info")
	// "查询链路", notes = "查询链路")
	public R list(int linkId) {
		final DeviceLink link = _devicelinkSvs.getById(linkId);
		return R.ok().putData(link);
	}

	@SysLogger("新增链路视图")
	@PostMapping("/add")
	// "新增链路视图", notes = "新增链路视图")
	public R add(@RequestBody DeviceLink devicelink) {
		devicelink.setCreateBy(getUser().getUsername());
		devicelink.setCreateTime(LocalDateTime.now());
		devicelink.setDeptId(getDeptId().intValue());
		Boolean b = devicelink.insert();
		return R.trueOrFalse(b);
	}

	@SysLogger("修改链路视图")
	@PostMapping("/update")
	// "修改链路视图", notes = "修改链路视图")
	public R update(@RequestBody DeviceLink devicelink) {
		Boolean b = devicelink.updateById();
		return R.trueOrFalse(b);
	}

	@SysLogger("删除链路视图")
	@PostMapping("/delete")
	// "删除链路视图", notes = "删除链路视图")
	public R delete(@RequestBody Integer linkId) {
		if (linkId > 0)
			_devicelinkSvs.removeById(linkId);
		return R.ok();
	}
}
